/**
 * @file
 * @auth jinguangguo
 * @date 2016/10/26
 */

import Vue from 'vue';
import moment from 'moment';
import Pager from '../../../grsc-base/component/Pager.vue';
import Loading from '../../../grsc-base/component/Loading.vue';
import NoData from '../../../grsc-base/component/NoData.vue';
import {PAGE_SIZE} from '../../../grsc-base/common/constants';

import tpl from './tpl.html';
import service from './service';

export default Vue.extend({
    template: tpl,
    components: {
        pager: Pager,
        loading: Loading,
        noData: NoData
    },
    data() {
        return {
            moment: moment,
            list: null,
            isLoading: false,
            condition: {
                pageNo: 1,
                pageSize: PAGE_SIZE,
                topStatus: ''   // 状态, YES:置顶, NO:不置顶
            },
            pageNum: 0
        }
    },
    computed: {

    },
    created() {
        this.fetchList();
    },
    methods: {
        
        /**
         * 获取数据列表
         */
        fetchList() {
            this.isLoading = true;
            let param = {
                pageNo: this.condition.pageNo,
                pageSize: this.condition.pageSize
            };
            if (this.condition.topStatus !== '') {
                param.topStatus = this.condition.topStatus;
            }
            service.noticeList(param).done((rep) => {
                this.isLoading = false;
                if (rep.code == window.CODE.SUCCESS) {
                    this.list = rep.data.list;
                    this.pageNum = rep.data.pageNum;
                } else {
                    window.error(rep.msg);
                }
            }).fail((rep) => {

            });
        },

        /**
         * 跳转到公告详情
         * @param item
         */
        goDetail(item) {
            this.$router.push({
                name: 'detail',
                params: {
                    noticeId: item.noticeId
                }
            });
        },

        /**
         * 分页
         * @param pageNo
         */
        changePage(pageNo) {
            this.condition.pageNo = pageNo;
            this.fetchList()
        }

    }
});